<div class="west_all" style="padding:0px">&nbsp;</div>
<div class="center_all" style="padding:0px">
    <div class="center_n" style="background-image: url(./../theme/default/images/main/pane_top.png)"></div>
    <div class="center_e" style="background-image: url(./../theme/default/images/main/pane_left.png)"></div>
    <div class="center_c" style="">    
        <div class="center_c_n">
        	<div style="position:relative;float:left;clear:left:top:0px;left:5px;line-height:25px;line-height:30px\9">${list.name}</div>
            <div class="toolbar">
                <ul class="program_toolbar" id="mainButton">
                
                    <#list common_func_list as comFunc>
                        <#assign show="0">
                        <#list feature_list as feature>
                            <#if comFunc.function.name==feature.code>
                                <#assign show="1">
                            </#if>
                        </#list>
                        <#if show?? && show=="1">
                            <#if comFunc.function.icon??>
                                <li class="${comFunc.function.icon}" onclick="javascript:processCommonFunc('${comFunc.function.id}',<#if comFunc.isBatch??>'${comFunc.isBatch}'<#else>'0'</#if>,<#if comFunc.function.messageType??>'${comFunc.function.messageType}'<#else>'0'</#if>,<#if comFunc.function.message??>'${comFunc.function.message}'<#else>''</#if>,<#if comFunc.function.forwardType??>'${comFunc.function.forwardType}'<#else>''</#if>,<#if comFunc.function.clearSession??>'${comFunc.function.clearSession}'<#else>'0'</#if>);return false;"><a href="javascript:void(0)"><img src="./../theme/default/images/main/blank.gif"><br/></a><div style="line-height:20px;float:left">${comFunc.function.displayName}</div></li>
                            <#else>
                                <li class="t8"><a href="javascript:void(0);"><img src="./../theme/default/images/main/blank.gif" onclick=""><br/></a></li>
                            </#if>
                     </#if>
                    </#list>
                </ul>
            </div>
        </div>
        <div class="center_c_c" style="padding:0px">
            <table id="GridTable"></table>
        </div>
    </div>
    <div class="center_w" style="background-image: url(./../theme/default/images/main/pane_right.png)"></div>
    <div class="center_s" style=" background-image: url(./../theme/default/images/main/pane_bottom.png)"></div>
</div>
<form id="searchForm" onSubmit="return false">
	<input type="hidden" id="businessProcessId" name="businessProcess.id" value="${businessProcess.id}">
    <input type="hidden" id="listId" name="list.id" value="${list.id}">
    <input type="hidden" id="id" name="id">
    <input type="hidden" id="functionId" name="function.id" value="${function.id}">
    <#if list.linkOperate??>
    <input type="hidden" id="hiddenLinkOperate" name="linkOperate" value="${list.linkOperate}">
    </#if>
    <input type="hidden" id="status" name="taskStatus">
     <#list query_field_list as queryField>
    	 <#if queryField.hidden?? && queryField.hidden=="1">
    		 ${queryField.content}
         </#if>
     </#list>
 </form>  
<form id="hiddenForm">
<#if paramsMap??>
	<#list paramsMap?keys as key>
		<#if paramsMap[key].field??>
		<input type=hidden name="paramsMap['${key}'].field.id" <#if paramsMap[key].field.id??> value="${paramsMap[key].field.id}"</#if>>
		<input type=hidden name="paramsMap['${key}'].value" <#if paramsMap[key].value??> value="${paramsMap[key].value}"</#if>></input>
		<input type=hidden name="paramsMap['${key}'].entityId" <#if paramsMap[key].entityId??> value="${paramsMap[key].entityId}"</#if>></input>
		</#if>
	</#list>
</#if>
</form>
<script language="javascript">
// JavaScript Document
$(function(){
    layout();
    loadGrid();
    /*reloadTree("1");*/
   $("#search").click(function(){ 
	
	    var name = $("#name").val();	  
		$("#GridTable").treegrid('unselectAll');

		if(name =='')
			return;
		
		var nodes = $('#GridTable').treegrid('getChildren');
	    var top =0;	    
	    var cells=  $(".datagrid-cell");
	    if(cells.length >0)
	    {
	      cellheight = cells.eq(0).outerHeight();
	    }	  
	    var first = true;
		for(var i=0; i<nodes.length; i++){
				
				if(nodes[i].name.indexOf(name) >=0)
				{	if(first)
					{
					top = cellheight*(i);
					first = false;
					}
				
					$("#GridTable").treegrid('select', nodes[i].id);
				}
		}
	    $(".datagrid-body").scrollTop(top);
		
	 });

	document.getElementsByTagName('form')[0].onkeydown = function(e){
		  var e = e || event;
		  var keyNum = e.which || e.keyCode;
		  if(keyNum==13){
			  $("#GridTable").click();
			  return false;
		  }
		  return true;
		};
        resizeDatagrid();
});

function process(funcId,messageType,message,forwardType,clearSession) {
      ${"$('#functionId')"}.val(funcId);
      var url = TDQS.CONTEXT_PATH+'business/process?tdqssid='+TDQS.SESSION_ID+ "&function.id="+${"$('#functionId')"}.val()+"&businessProcess.id="+${"$('#businessProcessId')"}.val()+"&list.id="+$('#listId').val()+'&'+$('#hiddenForm').serialize();
      if($('#id').val()!='') {
          url += ("&id="+$('#id').val());
      }
      if('1'==clearSession) {
      	url += "&clearSession=true";
      }
      url += "&date="+new Date().toLocaleString();
      if(!message||message=='') {
            message = '确定要执行操作吗？';
      }
      if(messageType && messageType=='1') {
          jConfirm(message, '确认对话框 ', function(r) {
						if(r){
							if(forwardType && forwardType=='2') {
                            	executeAjaxFunction(url);
                            }
                            else {
                            	document.location.href = url;
                            }
                        }else{
                            return false;
                        }
		  });
      }
      else {
            if(forwardType && forwardType=='2') {
                executeAjaxFunction(url);	
	        }
	        else {
	        	document.location.href = url;
	        }
      }
}
function executeAjaxFunction(url) {
	$.tdqsAjax({
		type: "post",
		dataType: "json",
		url: url,
		success:function(json) {
			if(json.data && json.data.type && json.data.type=='2' && json.data.resultData){
				jAlert(json.data.resultData,'提示',function(){
					//$('#GridTable').treegrid("tdqsReload");
					$('#GridTable').treegrid('refresh', null);
				});
			}
			else {
				$('#GridTable').treegrid("tdqsReload");
			}
			${"$('#id')"}.val('');
		}
	});
}
function processRowFunc(id,funcId,status,messageType,message,forwardType,clearSession) {
     ${"$('#id')"}.val(id);
     if(status && status!=''){
     	$('#status').val(status);
     }
     process(funcId,messageType,message,forwardType,clearSession);
}

function processCommonFunc(funcId,isBatch,messageType,message,forwardType,clearSession) {
   if(isBatch && isBatch=='1') {
          var select = $('#GridTable').treegrid('getSelections');
          var primaryValue = "";
          if (select && select != "") {
              for ( var i = 0; i < select.length; i++) {
                  if (i < select.length - 1) {
                       primaryValue += eval('select[i].id')+ ",";
                                
                   } else {
                        primaryValue += eval('select[i].id');
                   }
               }
           }
           if(!primaryValue || primaryValue=='') {
              jAlert('请选择${businessProcess.businessObj.desc}！','提示',function(){});
              return false;
           }
        $('#id').val(primaryValue);
    }
      process(funcId,messageType,message,forwardType,clearSession);
}

//z_tree data start
var zTree1;

var setting = {
    showLine: true
};

function showMenu(){
    
}
function loadGrid(){
      $('#GridTable').treegrid({
				width:700,
				height:350,
				collapsible:true,
				nowrap: false,
				rownumbers: true,
				singleSelect:true,
				loadMsg:'数据加载中，请稍候...', 
				url:TDQS.CONTEXT_PATH+'business/treelist.action?ajaxLoadType=1&tdqssid='+TDQS.SESSION_ID,
				queryParams:getFormParams('searchForm'),
				idField:'id',
				treeField:'id',
            frozenColumns:[[
            	<#assign idIndex=0>
                <#list listFields as listField>
                <#if listField.frozen?? && listField.frozen=='1' && (!listField.isHidden?? || listField.isHidden=='0')>
                {
                <#if idIndex = 0>
                	field : 'id',
                <#else>
                	field : '${listField.field.name}',
                </#if>
                 title : '${listField.title}',
                 width : ${listField.width},
                 defaultValue : <#if listField.defaultValue??>'${listField.defaultValue}'<#else>''</#if>,
                 align : <#if listField.align??>'${listField.align}'<#else>'center'</#if>,
                 formatter:function(value, row, index){
                     var fieldValue = '';
                     if(row.fieldMap['${listField.field.name}'] && row.fieldMap['${listField.field.name}'].value) {
                         fieldValue = row.fieldMap['${listField.field.name}'].value;
                     }
                     var displayValue = '';
                     if(row.fieldMap['${listField.field.name}'] && row.fieldMap['${listField.field.name}'].displayValue) {
                         displayValue = row.fieldMap['${listField.field.name}'].displayValue;
                     }
                     if(displayValue && displayValue!=null && displayValue!='') {
                        fieldValue = displayValue;
                     }
                     if(fieldValue=='') {
                         fieldValue = '&nbsp;';
                     }
                     if(row.editStatusFunction && row.editStatusFunction.id) {
                        var value = "<a href=\"javascript:void(0);\" onclick=\"processRowFunc('"+row.id+"','"+row.editStatusFunction.id+"','"+""+"','"+""+"','"+""+"','"+""+"','"+row.editStatusFunction.clearSession+"');return false;\">"+fieldValue+"</a>";
                         return value;
                     }
                     return fieldValue;
                 }
                } 
                <#assign idIndex=idIndex+1>
                </#if>
                </#list>
                ] ],
            columns:[ [ 
            	<#assign index=0>
                <#list listFields as listField>
                <#if !listField.frozen?? || listField.frozen=='0' && (!listField.isHidden?? || listField.isHidden=='0')>
                <#if index gt 0>
                ,
                </#if>
                {
                    field : '${listField.field.name}',
                     title : '${listField.title}',
                     width : ${listField.width},
                     defaultValue : <#if listField.defaultValue??>'${listField.defaultValue}'<#else>''</#if>,
                     align : <#if listField.align??>'${listField.align}'<#else>'center'</#if>,
                     //sortable : <#if listField?? && listField.sortable?? && listField.sortable=="1">true<#else>false</#if>,
                     formatter:function(value, row, index){
                          var fieldValue = '';
                         if(row.fieldMap['${listField.field.name}'] && row.fieldMap['${listField.field.name}'].value) {
                             fieldValue = row.fieldMap['${listField.field.name}'].value;
                         }
                         var displayValue = '';
                         if(row.fieldMap['${listField.field.name}'] && row.fieldMap['${listField.field.name}'].displayValue) {
                             displayValue = row.fieldMap['${listField.field.name}'].displayValue;
                         }
                         if(displayValue && displayValue!=null && displayValue!='') {
                             fieldValue = displayValue;
                         }
                         if(fieldValue=='') {
                             fieldValue = '&nbsp;';
                         }
                         <#if listField?? && listField.field.isEntity?? && listField.field.isEntity=="1" && listField.entityId?? && listField.linkFunction?? && listField.linkFunction.id?? && listField.linkable?? && listField.linkable>
                         	 var value = "<a href=\"javascript:void(0);\" onclick=\"processRowFunc('"+listField.entityId+"','"+listField.linkFunction.id+"');return false;\">"+fieldValue+"</a>";
                         	 return value;
                         </#if>
                         return fieldValue;
                     }
                }
                <#assign index=index+1>
                </#if>
                </#list>
                <#if list.allowOperColumn?? && list.allowOperColumn=="1">
                ,            
                 {    
                    field : 'opt',
                    title : '操作',
                    width : 200,
                    align : 'center',
                    rowspan : 2,
                    formatter:function(value, row, index){
                        var opers = '';
                        if(row && row.listFunctionList) {
                            for(var i=0,l=row.listFunctionList.length;i<l;i++) {
                                 var func = row.listFunctionList[i];
                                 var funcId = '';
                                 var messageType = '';
                                 var message = '';
                                 var funcName = '';
                                 var forwardType = '';
                                 var clearSession = '';
                                 if(func) {
                                     if(func.id) {
                                         funcId = func.id;
                                     }
                                     if(func.messageType) {
                                         messageType = func.messageType;
                                     }
                                     if(func.message) {
                                         message = func.message;
                                     }
                                     if(func.displayName) {
                                         funcName = func.displayName;
                                     }
                                     else if(func.desc) {
                                         funcName = func.desc;
                                     }
                                     if(func.forwardType) {
                                     	forwardType = func.forwardType;
                                     }
                                     if(func.clearSession) {
                                         clearSession = func.clearSession;
                                     }
                                 }
                                 if(!row.editStatusFunction || row.editStatusFunction.id !== func.id) {
	                                 opers += "<a href=\"javascript:void(0)\" onclick=\"javascript:processRowFunc('"+row.id+"','"+funcId+"','"+status+"','"+messageType+"','"+message+"','"+forwardType+"','"+clearSession+"');return false;\">"+funcName+"</a>";
                                 	opers += "&nbsp;&nbsp;";
	                             }
                            }
                        }
                        if(opers=='') {
                             opers = '&nbsp;';
                        }
                        return opers; 
                    }
                }
                </#if>
                ] ],
           		onLoadSuccess: function(row)
				{				       
						 resizeDatagrid();
						 $('#GridTable').treegrid('collapseAll');
						 
				},
				onBeforeLoad: function(row ,param)
				{		 			
					 if(row){
				      $('#GridTable').treegrid('options').queryParams = {"id":row.id};		      
				     }else
				     {
				      $('#GridTable').treegrid('options').queryParams ={};
				     }
				}
        });       
}

function resizeDatagrid(){
    $('#GridTable').datagrid("autoresizeForTreeGrid");
}
var mainLayout;
var centerContentLayout;
var contentLayout;
function layout(){
        var toggle_we        = '<div class="btnToggler_we"></div>'
        , toggle_w            = '<div class="btnToggler_w"></div>'
        , btnToggler_se        = '<div class="btnToggler_se"></div>'
        , btnToggler_s        = '<div class="btnToggler_s"></div>'
        
        $('body').layout({
            defaults:{
                onresize_end:    resizeDatagrid
                ,onclose_end:    resizeDatagrid  
            }
            ,center:{
                paneSelector:    ".center_all" 
            }
            ,west:{
                     size:    10
                ,    paneSelector:    ".west_all" 
                ,    spacing_open:    0
                ,    spacing_closed:   0        
                ,    togglerLength_closed:        0
                ,    togglerLength_open:       0
            }
        });

        $('div.center_all').layout({
            center__paneSelector:    ".center_c" 
        ,   north__size:    3
        ,    north__paneSelector:    ".center_n" 
        ,    north__spacing_open:    0
        ,    north__spacing_closed:    0        
        ,   south__paneSelector:    ".center_s"
        ,    south__size:    3
        ,    south__maxSize:            3
        ,    south__spacing_open:    0
        ,    south__spacing_close:    0
        ,    south__closable:        false
        ,    south__resizable:        false
        ,   east__size:    3
        ,    east__paneSelector:    ".center_e" 
        ,    east__spacing_open:    0
        ,    east__spacing_closed:    0        
        ,   west__size:    3
        ,    west__paneSelector:    ".center_w" 
        ,    west__spacing_open:    0
        ,    west__spacing_closed:    0    
        });
        $(".center_s,.center_n,.center_e,.center_w").css({overflow:"hidden"});

        $('div.center_c').layout({
            center:{
                paneSelector:    ".center_c_c" 
            }
            ,north:{
                     paneSelector:    ".center_c_n"
                ,    size:    30
                ,    spacing_open:    0
                ,    spacing_closed:    0            
            } 
         });
        $(".center_c_n").css({overflow:"hidden"});
        
}
</script>                                                                                                                                                                             